﻿using UnityEngine;

// A direction for each MazeCellEdge
public enum MazeDirection {
	North,
	East,
	South,
	West
}

public static class MazeDirections {
	// There are four directions available
	public const int count = 4;

	// Picks a random direction.
	public static MazeDirection RandomValue {
		get {
			return (MazeDirection)Random.Range (0, count);
		}
	}

	// The int vector representation of each direction.
	private static IntVector2[] vectors = {
		new IntVector2(0, 1),
		new IntVector2(1, 0),
		new IntVector2(0, -1),
		new IntVector2(-1, 0),
	};

	// Converts a direction to an IntVector2.
	public static IntVector2 ToIntVector2 (this MazeDirection direction) {
		return vectors[(int)direction];
	}

	// An array of directions opposite the set up.
	private static MazeDirection[] opposites = {
		MazeDirection.South,
		MazeDirection.West,
		MazeDirection.North,
		MazeDirection.East
	};

	// Return the opposite of the given direction
	public static MazeDirection GetOpposite (this MazeDirection direction) {
		return opposites [(int)direction];
	}

	// Is the second direction the opposite of the first one?
	public static bool isOpposite(this MazeDirection direction1, MazeDirection direction2) {
		return GetOpposite(direction1) == direction2;
	}

	// Rotate by a given amount.
	private static Quaternion[] rotations = {
		Quaternion.identity,
		Quaternion.Euler (0f, 0f, 90f),
		Quaternion.identity,
		Quaternion.Euler (0f, 0f, 90f)
	};

	// Return the given rotation.
	public static Quaternion ToRotation (this MazeDirection direction) {
		return rotations[(int)direction];
	}

}
